package com.cdream.basic.algorithm.leetcode.sort;

/**
 * @author cdream
 * @date 10/25/21
 */
public class Question240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int[] start = new int[]{matrix.length-1,0};
        int m = matrix.length;
        int n = matrix[0].length;
        while(start[0]>=0 && start[1]<=n-1) {
            int num = matrix[start[0]][start[1]];
            if(num == target) {
                return true;
            } else if(num > target){
                start[1]--;
            }else {
                start[0]++;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        boolean b = new Question240().searchMatrix(new int[][]{{1, 4, 7, 11, 15}, {2, 5, 8, 12, 19}, {3, 6, 9, 16, 22}, {10, 13, 14, 17, 24}, {18, 21,
                23, 26,
                30}}, 5);
    }
}
